import {login} from '@/api/user'
import { getToken, setToken } from '@/utils/storage'

export default {
  namespaced: true,
  state () {
    return {
      token: getToken()
    }
  },
  mutations: {
    setUserToken (state, payload) {
      state.token = payload
      setToken(payload)
    },
    resetToken(state) {
			state.token = null
			delToken()
		},
		setUser(state, userInfo) {
			state.userInfo = userInfo
		}
  },
  actions: {
    async loginAction (context, payload) {
      const res = await login(payload)
      context.commit('setUserToken', res.data.token)
    }
  }
}